package com.franklin.java.service.database;

import com.franklin.java.service.database.ic.DataSourceServiceForIC;
import com.franklin.java.service.database.iu.DataSourceServiceForIU;
import com.franklin.java.utils.ProjectUtils;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;


/**
 * @author Franklin
 * @since 2021/8/27 15:53
 */
public class DataSourceServiceSupport implements DataSourceService{

    private static DataSourceService realHandler;

    static {
        //兼容IU 以及 IC
        if (ProjectUtils.hasDatabaseTool()){
            realHandler = new DataSourceServiceForIU();
        }else {
            realHandler = new DataSourceServiceForIC();
        }
    }

    public static DataSourceServiceSupport getInstance(){
        return ServiceManager.getService(DataSourceServiceSupport.class);
    }

    @Override
    public DatabaseHandler getDatabaseHandler(PsiElement psiElement){
        return realHandler.getDatabaseHandler(psiElement);
    }

    @Override
    public MyJdbcConsole getJdbcConsole(Project project, String sql) {
        return realHandler.getJdbcConsole(project, sql);
    }

}
